package com.example.clocktest

import android.content.Context
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

class AddCookiesInterceptor() : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        val sharedPreferences = MyApp.getContext().getSharedPreferences("cookie_prefs", Context.MODE_PRIVATE)
//        val cookie = sharedPreferences.getString("cookie", "")
        val cookie = sharedPreferences.getString("Cookie", "JSESSIONID=0539CCDFBFEED2B63CFFFF285A996E6D")
        if (!cookie.isNullOrEmpty()) {
            builder.addHeader("Cookie", cookie)
        }
        return chain.proceed(builder.build())
    }
}